package com.idev.module.girl.controller;

import com.github.pagehelper.Page;
import com.idev.common.helper.ServiceManager;
import com.idev.module.girl.domain.Girl;

import org.apache.log4j.Logger;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by yigeyanse on 2017/6/14.
 */
@RestController
@RequestMapping(value="/girl")
@EnableAutoConfiguration
public class GirlController {

    private static final Logger logger = Logger.getLogger(GirlController.class);

    /*@Autowired
    private GirlService girlService;*/

    @RequestMapping(value="/say")
    public String sayHi(){
        logger.info("222");
        return "hi";
    }

    @RequestMapping(value = "/findGirlById/{id}")
    public Girl findGirlById(@PathVariable Integer id){
        //return girlService.findGirlById(id);
        return ServiceManager.girlService.findGirlById(id);
    }

    @RequestMapping(value="/insertGirl",method = RequestMethod.POST)
    public void insertGirl(Girl girl){
        Girl newGirl = new Girl();
        newGirl.setAge(girl.getAge());
        newGirl.setCupSize(girl.getCupSize());
        ServiceManager.girlService.addGirl(newGirl);
    }

    /**
     * 推荐
     * @param model
     * @param pageNum
     * @return
     */
    @RequestMapping("/index/{pageNum}")
    public List<Girl> findAllGirls(ModelMap model,@PathVariable Integer pageNum){

        Page page = ServiceManager.girlService.findAllGirls(pageNum);
        model.put("pages",page.getPages());
        model.put("total",page.getTotal());
        System.out.println("pages:"+page.getPages()+";total:"+page.getTotal());
        return page.getResult();
    }

}
